import defaultState from '../state/staff'
import { fromJS } from 'immutable'

const reducer = (state = defaultState, action) => {
  const type = action.type
  const data = action.data || ''

  switch (type) {
    case 'stafflist':
      let newState = state.set('stafflist', fromJS(data))
      return newState
    case "stafflistUpdate":
      let newState1 = state.set("stafflist",fromJS([...state.toJS().stafflist,...data]))
      return newState1
    case "addNewStaff":
     console.log(state.toJS().stafflist,data)
      let newStaffList = state.set("stafflist",fromJS([...state.toJS().stafflist,data]))
      return newStaffList

    case "templatelist":
      let newState2 = state.set("templatelist",fromJS(data))
      return newState2
    case "addTemplateList":
      let newState3 = state.set("templatelist",fromJS([...state.toJS().templatelist,data]))
      return newState3
    case "updateTemplateList":
      let newState4 = state.set("templatelist",fromJS([...state.toJS().templatelist,...data]))
      return newState4

      case "authoritylist":
        let newState5 = state.set("authority",fromJS(data))
        return newState5
      case "addAuthorityList":
        let newState6 = state.set("authority",fromJS([...state.toJS().authority,data]))
        return newState6
      case "updateAuthorityList":
        let newState7 = state.set("authority",fromJS([...state.toJS().authority,...data]))
        return newState7
    default:
      return state
  }
}

export default reducer